#!/usr/bin/perl
use warnings;
use strict;
use List::Util 'shuffle';
require 'appointment.pl';
if ($ARGV[0]){ print_5($ARGV[0]); }
else {         print_5();         }
#this ouputs the reservations for the next 5 days in a text file
#0 means free
#1 means taken
#2 means taken by you
sub print_5 {
	my $text = "";
	if ($_[0]){
		my $user = $_[0];
		foreach my $doctor (get_doctors()){
			$text .= $doctor . " - " . get_type_of_doctor($doctor) . ": ";
			for (my $i = 1; $i < 6; $i++){
				my @times = get_reserves(date($i), $doctor, $user);
				foreach my $time (@times){
					$text .= $time;
				}
				$text .= "+";
			}
			chop $text;
			$text .= "\n";
		}
		open(OUT, ">", "next5-$user.txt");
	}
	else {
		foreach my $choice (get_choices()){
			my ($marker, $name) = split /,/, $choice;
			$text .= $name . ($marker eq "d" ? " - " . get_type_of_doctor($name) : "") . ": ";
			for (my $i = 1; $i < 6; $i++){
				my @times = get_times($marker, date($i), $name);
				foreach my $time (@times){
					$text .= $time;
				}
				$text .= "+";
			}
			chop $text;
			$text .= "\n";
		}
		open(OUT, ">", "next5.txt");
	}
	print OUT $text;
	close(OUT);
}
